/* 
 * File:   cuda_tokenizer_util.h
 * Author: Chen Wei <acee06.weichen@gmail.com>
 *
 * Created on October 6, 2011, 2:09 PM
 */

#ifndef CUDA_TOKENIZER_UTIL_H
#define	CUDA_TOKENIZER_UTIL_H

#ifdef	__cplusplus
extern "C" {
#endif

__device__ const short _Cuda_ctype_table[256] = {
    0, /* 0x0 '\x00' */
    0, /* 0x1 '\x01' */
    0, /* 0x2 '\x02' */
    0, /* 0x3 '\x03' */
    0, /* 0x4 '\x04' */
    0, /* 0x5 '\x05' */
    0, /* 0x6 '\x06' */
    0, /* 0x7 '\x07' */
    0, /* 0x8 '\x08' */
    CUDA_CTF_SPACE, /* 0x9 '\t' */
    CUDA_CTF_SPACE, /* 0xa '\n' */
    CUDA_CTF_SPACE, /* 0xb '\v' */
    CUDA_CTF_SPACE, /* 0xc '\f' */
    CUDA_CTF_SPACE, /* 0xd '\r' */
    0, /* 0xe '\x0e' */
    0, /* 0xf '\x0f' */
    0, /* 0x10 '\x10' */
    0, /* 0x11 '\x11' */
    0, /* 0x12 '\x12' */
    0, /* 0x13 '\x13' */
    0, /* 0x14 '\x14' */
    0, /* 0x15 '\x15' */
    0, /* 0x16 '\x16' */
    0, /* 0x17 '\x17' */
    0, /* 0x18 '\x18' */
    0, /* 0x19 '\x19' */
    0, /* 0x1a '\x1a' */
    0, /* 0x1b '\x1b' */
    0, /* 0x1c '\x1c' */
    0, /* 0x1d '\x1d' */
    0, /* 0x1e '\x1e' */
    0, /* 0x1f '\x1f' */
    CUDA_CTF_SPACE, /* 0x20 ' ' */
    0, /* 0x21 '!' */
    0, /* 0x22 '"' */
    0, /* 0x23 '#' */
    0, /* 0x24 '$' */
    0, /* 0x25 '%' */
    0, /* 0x26 '&' */
    0, /* 0x27 "'" */
    0, /* 0x28 '(' */
    0, /* 0x29 ')' */
    0, /* 0x2a '*' */
    0, /* 0x2b '+' */
    0, /* 0x2c ',' */
    0, /* 0x2d '-' */
    0, /* 0x2e '.' */
    0, /* 0x2f '/' */
    CUDA_CTF_DIGIT|CUDA_CTF_XDIGIT, /* 0x30 '0' */
    CUDA_CTF_DIGIT|CUDA_CTF_XDIGIT, /* 0x31 '1' */
    CUDA_CTF_DIGIT|CUDA_CTF_XDIGIT, /* 0x32 '2' */
    CUDA_CTF_DIGIT|CUDA_CTF_XDIGIT, /* 0x33 '3' */
    CUDA_CTF_DIGIT|CUDA_CTF_XDIGIT, /* 0x34 '4' */
    CUDA_CTF_DIGIT|CUDA_CTF_XDIGIT, /* 0x35 '5' */
    CUDA_CTF_DIGIT|CUDA_CTF_XDIGIT, /* 0x36 '6' */
    CUDA_CTF_DIGIT|CUDA_CTF_XDIGIT, /* 0x37 '7' */
    CUDA_CTF_DIGIT|CUDA_CTF_XDIGIT, /* 0x38 '8' */
    CUDA_CTF_DIGIT|CUDA_CTF_XDIGIT, /* 0x39 '9' */
    0, /* 0x3a ':' */
    0, /* 0x3b ';' */
    0, /* 0x3c '<' */
    0, /* 0x3d '=' */
    0, /* 0x3e '>' */
    0, /* 0x3f '?' */
    0, /* 0x40 '@' */
    CUDA_CTF_UPPER|CUDA_CTF_XDIGIT, /* 0x41 'A' */
    CUDA_CTF_UPPER|CUDA_CTF_XDIGIT, /* 0x42 'B' */
    CUDA_CTF_UPPER|CUDA_CTF_XDIGIT, /* 0x43 'C' */
    CUDA_CTF_UPPER|CUDA_CTF_XDIGIT, /* 0x44 'D' */
    CUDA_CTF_UPPER|CUDA_CTF_XDIGIT, /* 0x45 'E' */
    CUDA_CTF_UPPER|CUDA_CTF_XDIGIT, /* 0x46 'F' */
    CUDA_CTF_UPPER, /* 0x47 'G' */
    CUDA_CTF_UPPER, /* 0x48 'H' */
    CUDA_CTF_UPPER, /* 0x49 'I' */
    CUDA_CTF_UPPER, /* 0x4a 'J' */
    CUDA_CTF_UPPER, /* 0x4b 'K' */
    CUDA_CTF_UPPER, /* 0x4c 'L' */
    CUDA_CTF_UPPER, /* 0x4d 'M' */
    CUDA_CTF_UPPER, /* 0x4e 'N' */
    CUDA_CTF_UPPER, /* 0x4f 'O' */
    CUDA_CTF_UPPER, /* 0x50 'P' */
    CUDA_CTF_UPPER, /* 0x51 'Q' */
    CUDA_CTF_UPPER, /* 0x52 'R' */
    CUDA_CTF_UPPER, /* 0x53 'S' */
    CUDA_CTF_UPPER, /* 0x54 'T' */
    CUDA_CTF_UPPER, /* 0x55 'U' */
    CUDA_CTF_UPPER, /* 0x56 'V' */
    CUDA_CTF_UPPER, /* 0x57 'W' */
    CUDA_CTF_UPPER, /* 0x58 'X' */
    CUDA_CTF_UPPER, /* 0x59 'Y' */
    CUDA_CTF_UPPER, /* 0x5a 'Z' */
    0, /* 0x5b '[' */
    0, /* 0x5c '\\' */
    0, /* 0x5d ']' */
    0, /* 0x5e '^' */
    0, /* 0x5f '_' */
    0, /* 0x60 '`' */
    CUDA_CTF_LOWER|CUDA_CTF_XDIGIT, /* 0x61 'a' */
    CUDA_CTF_LOWER|CUDA_CTF_XDIGIT, /* 0x62 'b' */
    CUDA_CTF_LOWER|CUDA_CTF_XDIGIT, /* 0x63 'c' */
    CUDA_CTF_LOWER|CUDA_CTF_XDIGIT, /* 0x64 'd' */
    CUDA_CTF_LOWER|CUDA_CTF_XDIGIT, /* 0x65 'e' */
    CUDA_CTF_LOWER|CUDA_CTF_XDIGIT, /* 0x66 'f' */
    CUDA_CTF_LOWER, /* 0x67 'g' */
    CUDA_CTF_LOWER, /* 0x68 'h' */
    CUDA_CTF_LOWER, /* 0x69 'i' */
    CUDA_CTF_LOWER, /* 0x6a 'j' */
    CUDA_CTF_LOWER, /* 0x6b 'k' */
    CUDA_CTF_LOWER, /* 0x6c 'l' */
    CUDA_CTF_LOWER, /* 0x6d 'm' */
    CUDA_CTF_LOWER, /* 0x6e 'n' */
    CUDA_CTF_LOWER, /* 0x6f 'o' */
    CUDA_CTF_LOWER, /* 0x70 'p' */
    CUDA_CTF_LOWER, /* 0x71 'q' */
    CUDA_CTF_LOWER, /* 0x72 'r' */
    CUDA_CTF_LOWER, /* 0x73 's' */
    CUDA_CTF_LOWER, /* 0x74 't' */
    CUDA_CTF_LOWER, /* 0x75 'u' */
    CUDA_CTF_LOWER, /* 0x76 'v' */
    CUDA_CTF_LOWER, /* 0x77 'w' */
    CUDA_CTF_LOWER, /* 0x78 'x' */
    CUDA_CTF_LOWER, /* 0x79 'y' */
    CUDA_CTF_LOWER, /* 0x7a 'z' */
    0, /* 0x7b '{' */
    0, /* 0x7c '|' */
    0, /* 0x7d '}' */
    0, /* 0x7e '~' */
    0, /* 0x7f '\x7f' */
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
    
#define Cuda_ISLOWER(c)  (_Cuda_ctype_table[(short)(c)] & CUDA_CTF_LOWER)
#define Cuda_ISUPPER(c)  (_Cuda_ctype_table[(short)(c)] & CUDA_CTF_UPPER)
#define Cuda_ISALPHA(c)  (_Cuda_ctype_table[(short)(c)] & CUDA_CTF_ALPHA)
#define Cuda_ISDIGIT(c)  (_Cuda_ctype_table[(short)(c)] & CUDA_CTF_DIGIT)
#define Cuda_ISXDIGIT(c) (_Cuda_ctype_table[(short)(c)] & CUDA_CTF_XDIGIT)
#define Cuda_ISALNUM(c)  (_Cuda_ctype_table[(short)(c)] & CUDA_CTF_ALNUM)
#define Cuda_ISSPACE(c)  (_Cuda_ctype_table[(short)(c)] & CUDA_CTF_SPACE)

    
extern int devID;
extern cudaDeviceProp prop;

__device__ char sharebuf[1024];

__device__ void *
cuda_malloc(int size) {
    return sharebuf;
}


#ifdef	__cplusplus
}
#endif

#endif	/* CUDA_TOKENIZER_UTIL_H */

